package drongo.desktop.undo
{
	/**
	 *操作链管理者 ，负责安排撤销与重做，不负责具体执行，具体执行内容应该由每个worker来做
	 * @author Grayness
	 */	
	public class OperationRecorder
	{
		/**
		 *根，除next对象外，不持有任何数据 
		 */		
		private  var root:OperationRecordNode;
		/**
		 *刚刚做完的操作 
		 */
		private  var current:OperationRecordNode;
		/**
		 *链接一个操作节点 
		 * @param command
		 * @param data
		 */
		public  function link(operation:IOperation):void
		{
			if(!root)
			{
				root=new OperationRecordNode(null,null,null);
				root.next=new OperationRecordNode(root,null,operation);
				current=root.next;
				return;
			}
			current.next=new OperationRecordNode(current,null,operation);
			current=current.next;
		}
		/**
		 *撤销一步操作
		 */		
		public  function undo():void
		{
			if(current&&current!=root)
			{
				current.operation.undo();
				current=current.last;
			}
		}
		/**
		 *重做一步操作 
		 * 
		 */		
		public  function redo():void
		{
			if(current&&current.next)
			{
				current.next.operation.redo();
				current=current.next;
			}
		}
		/**
		 *重置 
		 */
		public function reSet():void
		{
			current=root=null;
		}
	}
}